<template>
  <div class="loginall">
    <h1>登录</h1>
    <div class="oinp">
      <p>用户名：</p>
      <el-input v-model="username" placeholder="请输入用户名"></el-input>
    </div>
    <div class="oinp">
      <p>密码：</p>
      <el-input
        placeholder="请输入密码"
        v-model="password"
        show-password
      ></el-input>
    </div>
    <el-row>
      <el-button type="primary" round @click="login" :plain="true"
        >登录</el-button
      >
    </el-row>
    <div class="login-link">
      <el-link type="info">
        <router-link to="/register" tag="span">没有账号去注册</router-link>
      </el-link>
    </div>
  </div>
</template>

<script>
import api from "../../../http/apis/apis";
export default {
  data() {
    return {
      username: "zhangsan",
      password: "123",
    };
  },
  methods: {
    async login() {
      const { data } = await api.customer.login({
        username: this.username,
        password: this.password,
      });
      if (data.status) {
        localStorage.token = data.token;
        localStorage._id = data.data[0]._id;
        if (data.data[0].state == true) {
          this.$message({
            message: "登陆成功！",
            type: "success",
          });
          this.$router.push("/face");
        } else {
          this.$message({
            message: "你暂无权限登录，请联系官方！",
            type: "warning",
          });
        }
      } else {
        this.$message.error("登陆失败");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./login.scss";
</style>